<?php

/**
 * club actions.
 *
 * @package    cpfaizenay
 * @subpackage club
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class clubActions extends sfActions
{

  public function executeAutocompleteClub(sfWebRequest $request) {
      $this->forward404unless($request->isXmlHttpRequest());

      $this->getResponse()->setContentType ( 'application/json' );
      $results = Doctrine::getTable('Club')->retrieveClub($request->getParameter( 'q' ), $request->getParameter('limit'))->execute();

      $clubs = array();
      foreach ($results as $row) {
        $clubs[$row->getId()] = $row->getClubNumber() . " - " . $row->getName();
      }

      return $this->renderText (json_encode ($clubs));
  }

  public function executeAutocompleteCity(sfWebRequest $request) {
      $this->forward404unless($request->isXmlHttpRequest());

      $this->getResponse()->setContentType ( 'application/json' );
      $results = Doctrine::getTable('City')->retrieveCity($request->getParameter( 'q' ), $request->getParameter('limit'))->execute();

      $cities = array();
      foreach ($results as $row) {
        $cities[$row->getId()] = $row->getRawName();
      }

      return $this->renderText (json_encode ($cities));
  }
}
